class Solution
{
public:
    vector<int> findMissingAndRepeatedValues(vector<vector<int>> &grid)
    {
        int n = grid.size();
        vector<int> nums(n * n + 1);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                nums[grid[i][j]]++;
            }
        }
        int repeat = 0, miss = 0;
        for (int i = 1; i <= n * n; i++)
        {
            if (nums[i] == 0)
            {
                miss = i;
            }
            if (nums[i] == 2)
            {
                repeat = i;
            }
        }
        return {repeat, miss};
    }
};